package com.handler;

import com.google.gson.JsonObject;
import com.netty.handler.JSonStreamNettyHandler;

public class LoginHandler extends JSonStreamNettyHandler {
	
	private JsonObject json = null;
	
	public void doCheckUser() throws Exception
	{
		if (json.get("user").getAsString().equalsIgnoreCase("admin")
				&& json.get("pass").getAsString().equals("888")) {
		   this.jsonStream.setResult(true);
		   this.jsonStream.setResultMsg("身份验证成功!");
		}else
		{
			throw new Exception("身份验证失败!");
		}
	}
	
	public void doAction() throws Exception {
		json = this.jsonStream.getJSonObject();
		
		if (json.has("user") && json.has("pass")) {
			doCheckUser();
		}else
		{
			throw new Exception("请输入用户名和密码!");
		};
		
		json.addProperty("id", this.key);	
	}
}
